﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
//
//Description : Classe qui représente un champ éloigné d'un entité
//Auteur : Marc-Eric Boisvert
//Date Création : 31 mars 2008
//Révisions:
//

namespace Framework.Data.Core
{
    [Serializable()]
    public class ForeignField : EntityField, IForeignField
    {

        #region "Membres"

        //Valeur à afficher
        protected string _displayText = string.Empty;
        //Nom du champ de la clé primaire de la table source
        protected string _primaryKeyFieldName = string.Empty;
        //Nom du champ de la clé primaire de la table foreign
        protected string _foreignPrimaryKeyFieldName = string.Empty;
        //Type de l'entité foreign
        #endregion
        protected System.Type _foreignEntityType;

        #region "Constructeurs"

        /// <summary>
        /// Constructeur
        /// </summary>
        /// <param name="entity">Entité auquel ce champ appartient</param>
        /// <param name="fieldValueType">Type du champ</param>
        /// <param name="tableName">Nom de la table</param>
        /// <param name="databaseFieldName">Nom du champ dans la bd</param>
        /// <param name="fieldSize">Longueur du champ</param>
        /// <param name="isPrimaryKey">Indique si c'est une clé</param>
        /// <remarks></remarks>
        public ForeignField(IBaseEntity entity, Type fieldValueType, string tableName, string databaseFieldName, int fieldSize, bool isPrimaryKey, string primaryKeyFieldName, string foreignPrimaryKeyFieldName, System.Type foreignEntityType)
            : base(entity, fieldValueType, tableName.ToUpper(), databaseFieldName.ToUpper(), fieldSize, isPrimaryKey, false)
        {
            this._primaryKeyFieldName = primaryKeyFieldName.ToUpper();
            this._foreignPrimaryKeyFieldName = foreignPrimaryKeyFieldName.ToUpper();
            this._foreignEntityType = foreignEntityType;
        }

        #endregion

        #region "Méthodes"

        /// <summary>
        /// Fonction qui permet d'afficher la valeur du champ éloigné
        /// </summary>
        /// <returns>string</returns>
        /// <remarks></remarks>
        public override string ToString()
        {
            return base.ToString();
        }

        #endregion

        #region "IForeignField"

        public string PrimaryKeyFieldName
        {
            get { return this._primaryKeyFieldName; }
            set { this._primaryKeyFieldName = value; }
        }

        public string ForeignPrimaryKeyFieldName
        {
            get { return this._foreignPrimaryKeyFieldName; }
            set { this._foreignPrimaryKeyFieldName = value; }
        }

        public System.Type ForeignEntityType
        {
            get { return this._foreignEntityType; }
            set { this._foreignEntityType = value; }
        }

        #endregion

    }
}